# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=pyfasttextureutils
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}-git")
provides=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.r6.786d7cd
pkgrel=1
pkgdesc='Python module for quickly making certain modifications to images (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/LagoLunatic/PyFastTextureUtils"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "git")
_gitcommit=786d7cda8210ec2ad01f3397059ebf4d24365391
source=("git+https://github.com/LagoLunatic/PyFastTextureUtils#commit=${_gitcommit}"
"minmax.patch")
sha256sums=('5e03c06895113129fda7c846d219ba62e4b7f27f6e2fa472674be8b480bed807'
            'fc49c27aca6cfc6778dee41bca7aa2ef670117ed181e6eef7a0250bf2e16ab56')

pkgver() {
  cd $srcdir/PyFastTextureUtils
  printf "0.r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "$srcdir"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "PyFastTextureUtils" "python-build-${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  patch -Np2 -i ../minmax.patch
}

build() {
  cp -r "PyFastTextureUtils" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}"/python-build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
